<template>
  <div class="app-container layout-brand">
    <div class="operate-container">
      <el-button type="primary" @click="handleCreateProduct()" size="small">新 建</el-button>
    </div>
    <div class="table-container">
      <el-table :data="list" v-loading="listLoading" class="brand-table">
        <el-table-column label="名牌编号" width="200">
          <template slot-scope="scope">{{scope.row.brandCode}}</template>
        </el-table-column>
        <el-table-column label="名牌名称" width="200">
          <template slot-scope="scope">{{scope.row.brandName}}</template>
        </el-table-column>
        <el-table-column label="创建日期" width="200">
          <template slot-scope="scope">{{scope.row.createDate}}</template>
        </el-table-column>
        <el-table-column label="创建人" width="200">
          <template slot-scope="scope">{{scope.row.creator}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleAddGoods(scope.row)">添加商品</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :current-page.sync="listQuery.pageNum"
        :total="total"
      ></el-pagination>
    </div>
    <el-dialog
      :title="dialogOption.title"
      :visible.sync="dialogOption.dialogVisible"
      :close-on-click-modal="false"
      width="800px"
      class="form-dialog"
    >
      <hcbk-brand v-if="dialogOption.dialogVisible" @after-create="handleAfterCreate"></hcbk-brand>
    </el-dialog>
  </div>
</template>
<script>
import { getBrandList } from "@/api/brand";
import Brand from "./components/Brand.vue";
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10
};
export default {
  name: "product",
  components: {
    HcbkBrand: Brand
  },
  data() {
    return {
      dialogOption: {
        title: "新建品牌",
        dialogVisible: false,
        type: "create"
      },
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
      listLoading: true
    };
  },
  created() {
    this.getList();
  },
  watch: {},
  methods: {
    getList() {
      this.listLoading = true;
      this.listLoading = false;
      getBrandList(this.listQuery).then(res => {
        if (res.code === 200) {
          this.listLoading = false;
          this.list = res.data.list;
          this.total = res.data.total;
        }
      });
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    handleCreateProduct() {
      this.dialogOption = {
        title: "新建品牌",
        dialogVisible: true,
        type: "create"
      };
    },
    handleAfterCreate(result) {
      this.dialogOption.dialogVisible = false;
      if (result) {
        this.getList();
      }
    },
    handleAddGoods() {}
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.layout-brand {
  .brand-table.el-table /deep/ td {
    padding: 0px;
  }
  .text {
    padding: 4px 0px;
  }
}
.form-dialog /deep/ .el-dialog__body {
  padding: 18px;
}
</style>


